<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <span id="man" style="opacity: 1;">男孩</span>
    <span id="woman" style="opacity: 0;">女孩</span>
    <button onclick="handleToggleGender()">切换</button>
    <script>
        window.onload = function () {
            // 先获取男孩女孩的元素
            const man = document.getElementById("man")
            const woman = document.getElementById("woman")
            window.handleToggleGender = function() {
                // 点击之前，先获取每个元素的显示情况
                const manOpacity = Number(man.style.opacity)
                const womanOpacity =Number(woman.style.opacity)
                // 改变之前的显示情况
                man.style.opacity = manOpacity === 0 ? 1 : 0
                woman.style.opacity = womanOpacity === 0 ? 1 : 0
            }
        }
    </script>
</body>
</html>